var ConsultInfo = {
    id: "ConsultTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

var myDate = new Date();
var month;
var day;
if ((myDate.getMonth() + 1) < 10) {
    month = "0" + (myDate.getMonth() + 1);
} else {
    month = "" + (myDate.getMonth() + 1);
}
if (myDate.getDate() < 10) {
    day = "0" + myDate.getDate();
} else {
    day = "" + myDate.getDate();
}

ConsultInfo.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '病历号', field: 'caseNo', align: 'center', valign: 'middle', sortable: true, width: 150},
        {title: '患者姓名', field: 'patientName', align: 'center', valign: 'middle', sortable: true, width: 150},
        {title: '性别', field: 'sex', align: 'center', valign: 'middle', sortable: true,width: 120},
        {title: '年龄', field: 'age', align: 'center', valign: 'middle', sortable: true, width: 120},
        {title: '手机号码', field: 'phone', align: 'center', valign: 'middle', sortable: true, width: 140},
        {
            title: '创建时间', field: 'createTime', align: 'center', valign: 'middle', sortable: true, width: 220,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {title: '患者来源一级', field: 'patientSourceLv1', align: 'center', valign: 'middle', sortable: true, width: 150},
        {title: '患者来源二级', field: 'patientSourceLv2', align: 'center', valign: 'middle', sortable: true, width: 150},
        {title: '患者来源三级', field: 'patientSourceLv3', align: 'center', valign: 'middle', sortable: true, width: 150},
        {
            title: '初诊日期', field: 'firstVisitTime', align: 'center', valign: 'middle', sortable: true, width: 200,
            formatter: function (value, row, index) {
                return value.substring(0, 10);
            }
        },
        {title: '预约项目', field: 'appointmentProject', align: 'center', valign: 'middle', sortable: true, width: 150},
        {title: '创建人', field: 'createUser', align: 'center', valign: 'middle', sortable: true, width: 150},
        {
            title: '预约时间', field: 'appointmentTime', align: 'center', valign: 'middle', sortable: true, width: 220,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {
            title: '挂号时间', field: 'registerTime', align: 'center', valign: 'middle', sortable: true, width: 220,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {title: '医生', field: 'doctor', align: 'center', valign: 'middle', sortable: true, width: 150},
        {title: '是否消费', field: 'isConsume', align: 'center', valign: 'middle', sortable: true, width: 120},
        {title: '咨询师', field: 'tcName', align: 'center', valign: 'middle', sortable: true, width: 150},
    ]
    return columns;
};

ConsultInfo.search = function () {
    ConsultInfo.table.refresh({query: ConsultInfo.formParams()});
};

$(document).keyup(function(event){
    if(event.keyCode ==13){
        ConsultInfo.search();
    }
});

$(function () {
    $("#startCreateTime").val(myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00");
    $("#endCreateTime").val(myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59");

    //采用定时器监听 时间内容是否变化
    var startCreateTimeTwo = $("#startCreateTime").val();
    var endCreateTimeTwo = $("#endCreateTime").val();

    setInterval(
        function () {//定时执行方法内容
            if ($("#startCreateTime").val() != startCreateTimeTwo || $("#endCreateTime").val() != endCreateTimeTwo) {//如果时间发生变化，就触发查询事件
                ConsultInfo.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                startCreateTimeTwo = $("#startCreateTime").val();
                endCreateTimeTwo = $("#endCreateTime").val();
            }
            /*if ($("#appointmentPayService").val() != oldAppointmentPayServiceValue || $("#appointmentPayService").val() != oldAppointmentPayServiceValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldAppointmentPayServiceValue = $("#appointmentPayService").val();
            }*/
            /*if ($("#oneChannel").val() != oldOneChannelValue || $("#oneChannel").val() != oldOneChannelValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldOneChannelValue = $("#oneChannel").val();
            }
            if ($("#twoChannel").val() != oldTwoChannelValue || $("#twoChannel").val() != oldTwoChannelValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldTwoChannelValue = $("#twoChannel").val();
            }
            if ($("#thrChannel").val() != oldThrChannelValue || $("#thrChannel").val() != oldThrChannelValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldThrChannelValue = $("#thrChannel").val();
            }*/

        }, 500);

    var defaultColunms = ConsultInfo.initColumn();
    var table = new BSTable(ConsultInfo.id, "/consultInfo/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(ConsultInfo.formParams());
    ConsultInfo.table = table.init();
    ConsultInfo.search();
});

ConsultInfo.formParams = function () {
    var queryData = {};
    queryData['startCreateTime'] = $("#startCreateTime").val();
    queryData['tcName'] = $("#tcName").val();
    queryData['caseNo'] = $("#caseNo").val();
    queryData['phone'] = $("#phone").val();
    queryData['patientName'] = $("#patientName").val();
    queryData['endCreateTime'] = $("#endCreateTime").val();
    queryData['reach'] = $("#reach").val();
    console.log(queryData);
    return queryData;
}
